package com.devops.service.impl;

import com.devops.entity.req.CmdReq;
import com.devops.entity.req.DockerReq;
import com.devops.service.DockerService;
import com.devops.service.SshService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DockerServiceImpl implements DockerService {

    @Autowired
    private SshService sshService;

    @Override
    public String getVersion(DockerReq dockerReq) throws Exception {
        CmdReq cmdReq = new CmdReq();
        cmdReq.setHostIp(dockerReq.getHostIp());
        cmdReq.setCmd("docker --version");
        String versionInfo = sshService.cmd(cmdReq);

        return versionInfo;
    }

    @Override
    public void install(DockerReq dockerReq) throws Exception {
        String hostIp = dockerReq.getHostIp();
        sshService.sftp(hostIp, "shell/installDocker.sh", "/usr/local/shell");
        sshService.shell(hostIp, "/usr/local/shell/installDocker.sh");
//        sshService.cmd;
    }

    @Override
    public void delete(DockerReq dockerReq) throws Exception {
        String hostIp = dockerReq.getHostIp();
        sshService.sftp(hostIp, "shell/deleteDocker.sh", "/usr/local/shell");
        sshService.shell(hostIp, "/usr/local/shell/deleteDocker.sh");
    }
}
